<!doctype html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
	<title>去保养-有人情味的保养</title>
	<meta name="keywords" content="去保养,汽车保养,汽车配件,汽车维修,养车,4S店品质,氦修驿站" />
    <meta name="description" content="上门取车保养、保养在线观看、咖啡馆里做保养、夜间保养" />
	<link rel="stylesheet" type="text/css" href="{:C('WEB_URL')}Public/css/base.css">
	<link rel="stylesheet" type="text/css" href="{:C('WEB_URL')}Public/mobile/css/master.css">
	<style>
		html,body{width:100%;height:100%;overflow-x:hidden;}
	</style>
<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "//hm.baidu.com/hm.js?11ad56ca0738ac14d150a362fca3e058";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>

</head>
	<body class="overflow-H">
		<header class="tcenter fs14">
			<a href="tel:4006730088" class="tel iconfont">&#xe610;</a>
			<a href="{:C('WEB_URL')}mobile/" class="iconfont fright">&#xe60f;</a>
			<a href="{:C('WEB_URL')}mobile/" class="iconfont fleft">&#xe612;</a>
			选择车型
		</header>
		<div class="step">
			<eq name="_SESSION['location']" value="3301">
	            <ul class="hz">
	                <li class="current"><span>1</span>选择车型</li>
	                <li><span>2</span>填写信息</li>
	                <li><span>3</span>订单完成</li>
	            </ul>
	        <else />
	            <ul>
	                <li class="current"<span>1</span>选择车型</li>
	                <li><span>2</span>填写信息</li>
	                <li><span>3</span>选择店铺</li>
	                <li><span>4</span>订单完成</li>
	            </ul>
	        </eq>
		</div>
		<div class="autoList show" id="J_autoList">
			<div class="listMain show" onclick="chooseAuto.autoList(1)">
	            <?php foreach($list as $key=>$value){ ?>
				<div class="letter">{$key}</div>
				 <?php foreach($value as $val){ ?>
				 <ul class="list img">
					<li onclick="chooseAuto.getAuto('{$val['brand_id']}',1)">
						<img src="{:C('WEB_URL')}{$val['brand_logo']}" />
						<span>{$val['brand_name']}</span>
						<i class="arrow">&#xe603;</i>
					</li>
				</ul>
				<?php  }} ?>
	        </div>
	        <div class="listMain" onclick="chooseAuto.autoList(2)">
	            <ul></ul>
	        </div>
	        <div class="listMain" onclick="chooseAuto.autoList(3)">
	            <ul></ul>
	        </div>
	        <div class="listMain" onclick="chooseAuto.autoList(4)">
	            <ul></ul>
	        </div>
	        <p class="clearfix"></p>
	    </div>

		<include file="Public/mobileHome" />

		<script>

		    var chooseAuto={
		        init:function(){
		            $("#J_autoList").children(".listMain").on("click",function(e){
		            	var index=$(e).index();
		            })
		            $("#J_selected").on("click",function(e){
		                if(e.target.tagName==="A"){
		                    var element=$(e.target).parent();
		                        index=element.index();

		                    if(index==0){
		                        $("#J_brandList").show();
		                        $("#J_autoList").hide();

		                        
		                    }else{
		                        element.remove();
		                        $("#J_autoList").find(".listMain").hide().eq(index*1-1).show();
		                    }

		                    //清除从首页传递过来的车型数据
		                    clearCookie("brand_id");
		                    clearCookie("autoId");
		                    
		                }
		            })

		            var brand_id=getCookie("brand_id");

		            if(brand_id!=null){
		                //chooseAuto.getAuto(brand_id,1,"homeTo");
		            }
		        },

		        //选择车品牌
		        chooseBrand:function(){
		        	$("#J_autoList").addClass("show").find(".listMain:eq(0)").addClass("show");
		        },

		        //选择车型
		        autoList:function(level){
		        	$("#J_autoList .listMain").each(function(i){
		        		if(i>level){
		        			$(this).removeClass("show");
		        		}
		        	})
		        },

		        //选择车型  step=0：查品牌；step=1：查车型；step=2:查排量；step=3:查年份
		        chooseAutoCurrent:{"brand_id":"","model_name":"","model_pl":"","model_year":""},
		        getAuto:function(id,step,brand_id){

		            //计算每一步需要查询的条件
		            var arr=["brand_id","model_name","model_pl","model_year"],
		                _t=this,
		                data={};
		            if(step==0){
		                this.chooseAutoCurrent={"brand_id":"","model_name":"","model_pl":"","model_year":""};
		            }else{
		                this.chooseAutoCurrent[arr[step-1]]=id;
		            }

		            if(typeof brand_id!="undefined"&&brand_id!="homeTo"){
		                this.chooseAutoCurrent["brand_id"]=brand_id;
		            }

		            for(var i=0;i<=step;i++){
		                if(this.chooseAutoCurrent[arr[i]]!=""&&i<step){
		                    data[arr[i]]=this.chooseAutoCurrent[arr[i]];
		                }
		            }

		            var url="{:C('WEB_URL')}mobile/getAuto.html";

		            $.ajax({
		                type:"post",
		                dataType:"json",
		                url:url,
		                data:data,
		                success:function(res){
		                    var html="";
		                    if(res.data==null){
		                        showMsgTip("抱歉，该品牌的车型正在完善中！",2000);
                    			return false;
		                    }else{
		                        html=_t.getAutoListHtml(res.data,step);
		                        if(step==1||typeof brand_id!="undefined"){
		                            $("#J_selected").html('<em>'+res.data[0]['brand_name']+'<a href="javascript:void(0)">×</a></em>');
		                        }

		                        if(step==2){
		                            $("#J_selected").append('<em>'+res.data[0]['model_name']+'<a href="javascript:void(0)">×</a></em>');
		                        }else if(step==3){
		                            $("#J_selected").append('<em>'+res.data[0]['model_pl']+'<a href="javascript:void(0)">×</a></em>');
		                        }else if(step==4){
		                            $("#J_selected").append('<em>'+res.data[0]['model_year']+'<a href="javascript:void(0)">×</a></em>');
		                        }

		                        //切换界面
		                        //$("#J_brandList").hide();
		                        //$("#J_autoList").show().find(".listMain").hide()
		                        $("#J_autoList").find(".listMain").eq(step*1).addClass("show").find("ul").html(html);

		                        //从首页带入品牌时自动获取车型
		                        if(brand_id=="homeTo"){
		                            var brand_name=getCookie("auto");
		                            if(brand_name!=null){
		                                chooseAuto.getAuto(brand_name,2);
		                            }
		                        }
		                    }
		                }
		            })
		        },
		        //转换车型数据成HTML
		        getAutoListHtml:function(data,step){

		            var arr=["brand_id","model_name","model_pl","model_year"],
		                html="",
		                arrTemp={},
		                len=data.length,
		                i=0;

		            for(;i<len;i++){
		                if(typeof arrTemp[data[i][arr[step]]]=="undefined"){
		                    var even=step!=3?"chooseAuto.getAuto('"+data[i][arr[step]]+"',"+(step+1)+")":"chooseAuto.confirmAuto('"+data[i]["model_id"]+"')";
		                    html+="<li onclick=\""+even+"\"><i>&#xe603;</i>"+data[i][arr[step]]+"</li>";
		                    arrTemp[data[i][arr[step]]]=true;
		                }
		            }
		            
		            return html;
		        },
		        confirmAuto:function(id){
		        	var back=getQuery("back");
		        	if(back=="home"){
		        		window.location.href="{:C('WEB_URL')}mobile/index.html?autoId="+id;
		        	}else{
		        		window.location.href="{:C('WEB_URL')}mobile/step2.html?autoId="+id;
		        	}
		            
		        }
		    }
		    chooseAuto.init();

		</script>
	</body>
</html>